package org.ligson.fwc.api.enums;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

/****
 * code定义规范6位：
 * 0XXXXX 系统级别错误
 * 1XXXXX 参数校验错误
 * 2XXXXX 业务校验错误
 */
public class BaseErrorCode {
    private String code;
    private String msg;

    private static Map<String, String> errorCodeMap = new HashMap<>();
    private static Logger logger = LoggerFactory.getLogger(BaseErrorCode.class);

    public static final BaseErrorCode SYS_ERROR = new BaseErrorCode("000000", "系统异常");
    public static final BaseErrorCode DATA_NULL = new BaseErrorCode("000001", "数据不存在");

    protected BaseErrorCode(String code, String msg) {
        this.code = code;
        this.msg = msg;
        if (errorCodeMap.containsKey(code)) {
            logger.error("code:{}-{}存在", code, msg);
        }
        errorCodeMap.put(code, msg);
    }

    public String getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }
}
